package br.com.paiva.container.dao.impl;

import java.util.List;

import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import br.com.paiva.container.Aeroporto;
import br.com.paiva.container.dao.AeroportoDAO;

@Service("aeroportoDAO")
public class AeroportoDAOHibernate extends BaseDAOHibernate implements AeroportoDAO{
	
	public List<Aeroporto> list() {
		return super.loadAll(Aeroporto.class);
	}

	public Aeroporto retrive(Long id) {
		return super.get(Aeroporto.class, id);
	}

	public void save(Aeroporto aeroporto) {
		this.getSession().flush();  
		this.getSession().clear();  
		this.saveOrUpdate(aeroporto);
	}

	public void evict(Object object) {
		// TODO Auto-generated method stub
		
	}

	public void delete(Long id) {
		// TODO Auto-generated method stub
		
	}
	
	public void delete(Object object) {
		this.delete(object);
		
	}

	@SuppressWarnings("unchecked")
	public List<String> searchAeroporto(String nome) {
		return this.getSession().createCriteria(Aeroporto.class)
		.setProjection(Projections.distinct(Projections.property("nome")))
		.add(Restrictions.ilike("nome",
				nome, MatchMode.ANYWHERE))
				.addOrder(Order.asc("nome")).list();
	}
	
}
